package pit.com.ordermobilesystem.http;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

import pit.com.ordermobilesystem.constant.OrderConstant;


public class OrderSystemHttpService implements OrderConstant{
	private HttpApi mHttpApi;
	private final String mApiBaseUrl;
	public final static String URL_GET_LIST_CATEGORY = "/index.php/mobile/getCategory";
	public final static String URL_GET_LIST_ITEM = "/index.php/mobile/getItems";
	public final static String URL_SUBMIT_ORDER = "/index.php/mobile/insertOrder";
	public final static String URL_GET_LIST_STORE = "/index.php/mobile/getStores";
	public final static String URL_GET_LIST_NEWS = "/index.php/mobile/getNews";
	public final static String URL_LOGIN = "/index.php/mobile/login";
	public final static String URL_UPLOAD_IMAGE = "/index.php/mobile/uploadImage";
	public final static String URL_INSERT_GENERAL = "/index.php/mobile/insertGeneral";
	public final static String URL_UPDATE_GENERAL = "/index.php/mobile/updateGeneral";
	public final static String URL_DELETE_GENERAL = "/index.php/mobile/deleteGeneral";
	public final static String URL_SELECT_GENERAL = "/index.php/mobile/selectGeneral";
	public final static String URL_SELECT_SHOP = "/index.php/mobile/selectShops";
	
	public OrderSystemHttpService(String domain, String port) {
		mApiBaseUrl = "http://" + domain + ":" + port + "/"+NAME_SERVICE;
		mHttpApi = new HttpApiWithAuth();
	}

	private String fullUrl(String url) {
		return mApiBaseUrl + url;
	}
	
	  public JSONObject requestToService(String url_request, String data) throws HttpApiException, IOException, JSONException {
		    String url = fullUrl(url_request);
		    String response="";
		    if(data.equals(""))response=mHttpApi.doHttpGet(url);
		    else response=mHttpApi.doHttpPost(url, data);
		    return new JSONObject(response);
	 }
	
	  public JSONObject uploadFile(String url_request,String data, String filePath[]) throws HttpApiException, IOException, JSONException {
		    String url = fullUrl(url_request);
		    String response="";
		     response=mHttpApi.doHttpRequestMultipart(url, data, filePath);
		    return new JSONObject(response);
	 }	

}
